/**   
 * @Title: CommonQueryAction.java 
 * CopyRight(c)2010-DMX 
 */
package com.dmx.fw.web.struts2.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dmx.fw.bean.ColumnInfoBean;
import com.dmx.fw.bean.PageInfo;
import com.dmx.fw.bean.QueryInfoBean;
import com.dmx.fw.component.commonquery.QueryScriptDef;
import com.dmx.fw.constant.ViewConstant;
import com.dmx.fw.resource.SystemProperties;
import com.dmx.fw.security.bean.Operator;
import com.dmx.fw.service.interfaces.QueryService;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;

/** 
 * @Description: 通用查询Action，查询一般继承此类
 * @author: system
 * @date: 2006
 * @version V1.0 
 * 
 */
public class CommonQueryAction extends BaseAction{
	
	/** 
	 * @Description: 有关查询信息的封装的内部类
	 */
	public class QryConditionInfo implements java.io.Serializable{
		
		/** 
		 * @Fields formParamMap：
		 */
		public HashMap formParamMap;
		
		/** 
		 * @Fields extraParamMap：
		 */
		public HashMap extraParamMap;
		
		/** 
		 * @Fields busiId：查询的busiId标识，与配置文件一致
		 */
		public String busiId;
		
		/** 
		 * @Fields currentPageNo：查询当前页号
		 */
		public int currentPageNo;
		
		/** 
		 * @Fields act：执行方法
		 */
		public String act;
		
		/** 
		 * @Fields orderByScript：支持页面排序的order by script
		 */		
		public String orderByScript; 
		
		/**
		 * @serialField sortField:页面排序字段
		 */
		protected String sortField;
		
		/**
		 * @serialField sortMode:页面排序方式
		 */
		protected String sortMode;
		
		
		
		public String getAct() {
			return act;
		}
		public void setAct(String act) {
			this.act = act;
		}
		public String getBusiId() {
			return busiId;
		}
		public void setBusiId(String busiId) {
			this.busiId = busiId;
		}
		public int getCurrentPageNo() {
			return currentPageNo;
		}
		public void setCurrentPageNo(int currentPageNo) {
			this.currentPageNo = currentPageNo;
		}
		public HashMap getExtraParamMap() {
			return extraParamMap;
		}
		public void setExtraParamMap(HashMap extraParamMap) {
			this.extraParamMap = extraParamMap;
		}
		public HashMap getFormParamMap() {
			return formParamMap;
		}
		public void setFormParamMap(HashMap formParamMap) {
			this.formParamMap = formParamMap;
		}
		public String getOrderByScript() {
			return orderByScript;
		}
		public void setOrderByScript(String orderByScript) {
			this.orderByScript = orderByScript;
		}
		public String getSortField() {
			return sortField;
		}
		public void setSortField(String sortField) {
			this.sortField = sortField;
		}
		public String getSortMode() {
			return sortMode;
		}
		public void setSortMode(String sortMode) {
			this.sortMode = sortMode;
		}

		
	}

	private static final long serialVersionUID = -3650393211590248998L;
	
	private QueryService queryService;
	
	private String busiDataId;
	
	/** 
	 * @Fields encapType：查询结果的封装类型
	 */
	protected String encapType = QueryService.LIST_ENCAPSULATION;
	
	/** 
	 * @Fields qry_param_prefix：查询参数统一前缀
	 */
	protected String qry_param_prefix = "q_";
	
	protected static  final String COMMONQUERY_CONDITION_SESSION_NAME = ViewConstant.COMMONQUERY_CONDITION_SESSION_NAME; 
	
	/** 
	 * @Fields _extraParamsMap：用于保存扩展的查询参数，通过getInitExtraParamsMap获取
	 */
	protected HashMap _extraParamsMap = new HashMap();

	/** 
	 * @Fields cache：是否缓存查询条件，默认缓存
	 */
	protected boolean cache = true;
	
	/** 
	 * @Fields busiId：查询业务代码，用户获取定义的SQL
	 */
	protected String busiId;	
	
	/** 
	 * @Fields orderByScript：支持页面排序的order by script
	 */		
	protected String orderByScript; 
	
	/**
	 * @serialField sortField:页面排序字段
	 */
	protected String sortField;
	
	/**
	 * @serialField sortMode:页面排序方式
	 */
	protected String sortMode="desc";

	/** 
	 * @Fields currentPageNo：当前查询的页码
	 */ 
	protected int currentPageNo = 1;
	
	/** 
	 * @Fields formQryParamsMap: 查询参数Map
	 */
	protected HashMap formQryParamsMap = null;
	
	/** 
	 * @Fields paginationIdx: 分页form标识
	 */
	private int paginationIdx = 0;
	
	
	/** 
	 * @Fields pageInfo: 分页对象
	 */
	protected PageInfo pageInfo = new PageInfo(SystemProperties.getInstance().getPageSize());
	
	//业务ID，根据此ID从xml文件获得查询SQL
	public String getBusiId() {
		return busiId;
	}

	public void setBusiId(String busiId) {
		this.busiId = busiId;
	}

	public int getCurrentPageNo() {
		return currentPageNo;
	}

	public void setCurrentPageNo(int currentPageNo) {
		this.currentPageNo = currentPageNo;
	}

	public PageInfo getPageInfo() {
		return pageInfo;
	}

	public void setPageInfo(PageInfo pageInfo) {
		this.pageInfo = pageInfo;
	}
		
	public CommonQueryAction(){
		//init act'value
		act = "query";
	}
	
	/**
	 * @Description 查询执行方法
	 * @throws Exception
	 */
	public String doQuery() throws Exception{
		ActionContext ctx = ActionContext.getContext();			
		
		String qryParamPrefix = qry_param_prefix.toUpperCase();	
		HashMap allParamsMap = new HashMap();

		Iterator it = ctx.getParameters().keySet().iterator();
		while(it.hasNext()){
			String keyName = (String)it.next();
			if (keyName.toUpperCase().startsWith(qryParamPrefix)){
				String[] vals = (String[])(ctx.getParameters().get(keyName));					
				if (vals!=null && vals.length>0){
					allParamsMap.put(keyName,vals[0]);
				}
			}
		}	
		it = this._extraParamsMap.keySet().iterator();
		while(it.hasNext()){
			String keyName = (String)it.next();
			allParamsMap.put(keyName,(String)this._extraParamsMap.get(keyName));
		}

//		Add business data splite
		String temp_val=this.getBusiDataId();
		if(!temp_val.equals("-1")){
			allParamsMap.put("busiDateId", temp_val);
		}
		
		pageInfo.setCurrentPageNo(this.currentPageNo);
		if (pageInfo.getCurrentPageNo() <= 0)
			pageInfo.setCurrentPageNo(1);
		
		if(sortField!=null&&!sortField.trim().equals("")){
			orderByScript="order by "+sortField+" "+sortMode;
		}
		
		QryConditionInfo qryConditionInfo = new QryConditionInfo();
		qryConditionInfo.act = this.act;
		qryConditionInfo.busiId = this.busiId;
		qryConditionInfo.formParamMap = allParamsMap;
		qryConditionInfo.currentPageNo = pageInfo.getCurrentPageNo();
		qryConditionInfo.sortField=this.sortField;
		qryConditionInfo.sortMode=this.sortMode;
		qryConditionInfo.orderByScript=this.orderByScript;			
		if (this.isCache()){
			HashMap queryCacheMap = (HashMap)ctx.getSession().get(COMMONQUERY_CONDITION_SESSION_NAME);
			if (queryCacheMap==null){
				queryCacheMap = new HashMap();
			}
			queryCacheMap.put(this.busiId, qryConditionInfo);
			ctx.getSession().put(COMMONQUERY_CONDITION_SESSION_NAME,queryCacheMap);
		}
        
		//获得查询
		pageInfo = queryData(busiId, allParamsMap, pageInfo,this.encapType);	
		formQryParamsMap = allParamsMap;
		return null;
	}
	
	/**
	 * @Description 多次查询方法，结果可能从缓存中取出
	 * @throws Exception
	 */
	public String doReQuery() throws Exception{
		ActionContext ctx = ActionContext.getContext();
		HashMap queryCacheMap = (HashMap)ctx.getSession().get(COMMONQUERY_CONDITION_SESSION_NAME);
		if (queryCacheMap==null){
			return SUCCESS;
		}
		QryConditionInfo qryConditionInfo = (QryConditionInfo)queryCacheMap.get(this.busiId);
		if (qryConditionInfo==null){
			return SUCCESS;
		}		
		
		this.act = qryConditionInfo.act;
		this.currentPageNo = qryConditionInfo.currentPageNo;
		pageInfo.setCurrentPageNo(this.currentPageNo);
		this.sortField=qryConditionInfo.sortField;
		this.sortMode=qryConditionInfo.sortMode;
		this.orderByScript=qryConditionInfo.orderByScript;
		if ("noQuery".equals(act)){
			return SUCCESS;
		}

		HashMap allParamsMap = qryConditionInfo.formParamMap;	
		if (allParamsMap!=null){
			Iterator it = allParamsMap.keySet().iterator();
			while(it.hasNext()){
				String keyName = (String)it.next();
				String val = (String)allParamsMap.get(keyName);
				try{
					Method setField = this.getClass().getDeclaredMethod("set" +
							keyName.toUpperCase().charAt(0) +
							keyName.substring(1), String.class);
					if (setField!=null){
						setField.invoke(this,val);
					}
				}catch(Exception e){
					continue;
				}
			}
		}
		
//		Add business data splite
		String temp_val=this.getBusiDataId();
		if(!temp_val.equals("-1")){
			allParamsMap.put("busiDateId", temp_val);
		}

		pageInfo = queryData(busiId, allParamsMap, pageInfo,this.encapType);
		
		formQryParamsMap = allParamsMap;
		//doPagination(formParamsMap);
		return null;
	}
	
	/**
	 * @Description 不查询，直接返回
	 * @throws Exception
	 */
	public String doNoQuery() throws Exception{
		formQryParamsMap = null;
		return null;
	}
	public String execute() throws Exception {
		
		//不进行查询
		if ("noQuery".equals(act)){
			doNoQuery();
		}else if ("query".equals(act)){
			doQuery();			
		}else if ("reQuery".equals(act)){ //重新查询
			doReQuery();
		}else if ("changePage".equals(act)){
			if (this.cache){
				ActionContext ctx = ActionContext.getContext();
				HashMap queryCacheMap = (HashMap)ctx.getSession().get(COMMONQUERY_CONDITION_SESSION_NAME);
				if (queryCacheMap==null){
					return SUCCESS;
				}
				QryConditionInfo qryConditionInfo = (QryConditionInfo)queryCacheMap.get(this.busiId);
				if (qryConditionInfo==null){
					return SUCCESS;
				}
				if ("noQuery".equals(qryConditionInfo.act)){
					return SUCCESS;
				}
				qryConditionInfo.act = "query";
				qryConditionInfo.currentPageNo = this.currentPageNo;
				doReQuery();
			}else{
				doQuery();
			}
		}else if ("export".equals(act)){
			performExport();
			return "";
		}
		return SUCCESS;
	}
	
	/*protected PageInfo queryData(String busiId, HashMap paramsMap,PageInfo pageInfo){
		QueryInfoBean queryInfoBean = (QueryInfoBean)QueryScriptDef.getQueryInfo(busiId,ServletActionContext.getServletContext());
		return queryService.queryData(queryInfoBean, paramsMap, pageInfo,this.getEncapType());
	}*/
	
	protected PageInfo queryData(String busiId, HashMap paramsMap,PageInfo pageInfo,String encapType){
		QueryInfoBean queryInfoBean = (QueryInfoBean)QueryScriptDef.getQueryInfo(busiId);
		QueryInfoBean tempBean=new QueryInfoBean();
		try {
			BeanUtils.copyProperties(tempBean,queryInfoBean);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e);
		}
		if(this.orderByScript!=null) 
			tempBean.setOrderByScript(orderByScript);
		return queryService.queryData(tempBean, paramsMap, pageInfo,encapType);
	}
	
	/** 
	 * @Fields pagination：拼好的分页结果
	 */
	private String pagination;
	
	
	/**
	* <p>分页方法</p>
    *   <table width="100%" border="0" cellspacing="0" cellpadding="0">
    *        <tr>
    *          <td height="25">&nbsp;</td>
    *          <td width="20" align="left"><img src="../../images/button_01.gif" width="15" height="15" style="cursor:hand;"/></td>
    *          <td width="20" align="left"><img src="../../images/button_02.gif" width="15" height="15" style="cursor:hand;"/></td>
    *          <td width="35" align="center"><input name="textfield7222" type="text" size="4" style="width:25px;height:12px;" class="textsmallbox_css" onfocus="this.style.background='white';" onblur="this.style.background='D7D2D3';"/></td>
    *          <td width="25" align="left">/15</td>
    *          <td width="20" align="left"><img src="../../images/button_03.gif" width="15" height="15" style="cursor:hand;"/></td>
    *          <td width="20" align="left"><img src="../../images/button_04.gif" width="15" height="15" style="cursor:hand;"/></td>
    *        </tr>
    *    </table>
    *    changePage(obj,action,busiId,toPage,otherParam)
	* @param paramsMap
	*/
	protected String doPagination(HashMap paramsMap){
		
		HttpServletRequest req = ServletActionContext.getRequest();
		String root = req.getContextPath();
		
		int totalPage = pageInfo.getTotalPage();
		int currentPageNo = pageInfo.getCurrentPageNo();
		
				
		if (totalPage<=0){
			currentPageNo = 1;
			totalPage=1;
		}
		
		String formName = "pagination" + paginationIdx;
		paginationIdx = paginationIdx + 1;
		
		ActionContext ctx = ActionContext.getContext();
		ActionInvocation ai = (ActionInvocation) ActionContext.getContext().get(ActionContext.ACTION_INVOCATION);
		String nameSpace = ai.getProxy().getNamespace()==null?"":ai.getProxy().getNamespace();
		if(!nameSpace.equals("")){
			nameSpace = nameSpace.substring(1)+"/";
		}

		StringBuffer otherParam = new StringBuffer();
		
		StringBuffer buffer = new StringBuffer();
		buffer.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n")
			  .append("<form name=\"" + formName + "\" method=\"post\" " +
			  		//"action=\"" + nameSpace + ctx.getName() + ".action\" " +
			  				" onsubmit='return false;'>\n");
		if (paramsMap!=null){
			Iterator it = paramsMap.keySet().iterator();
			while(it.hasNext()){
				String keyName = (String)it.next();
				String val = (String)paramsMap.get(keyName);
				buffer.append("        <input name=\""+keyName+"\" type=\"hidden\" value=\""+val+"\">\n");
				otherParam.append("&"+keyName+"="+val);
			}	
		}
		buffer.append("        <input name=\"busiId\" type=\"hidden\" value=\""+this.getBusiId()+"\">\n");
		buffer.append("        <input name=\"act\" type=\"hidden\" value=\"changePage\">\n");
		buffer.append("        <input name=\"currentPageNo\" type=\"hidden\" value=\""+currentPageNo+"\">\n");
	    buffer.append("  <tr height=5><td colspan=7></td></tr>\n"); 
	    buffer.append("  <tr valign='middle'>\n") 
			  .append("    <td align='right'>"+ getText("label.pagination.totalRecord",new String[]{String.valueOf(pageInfo.getTotalResult())}) +"&nbsp;</td>\n")
	          .append("    <td width=\"20\" align=\"left\" valign='middle'><img src=\"" + root + "/core/images/button_01.gif\" width=\"15\" height=\"15\" style=\"cursor:hand;\"");
	          //设置第一页
		  	    if (currentPageNo <=1 || totalPage <=1){
			    }else{
			    	buffer.append(" onclick=\"document."+formName+".currentPageNo.value='1';changePage('"+ nameSpace + ctx.getName() + ".action','"+this.getBusiId()+"','1','"+otherParam.toString()+"');\"");	
			    }
		  	  buffer.append("/></td>\n")
	          .append("    <td width=\"20\" align=\"left\" valign='middle'><img src=\"" + root + "/core/images/button_02.gif\" width=\"15\" height=\"15\" style=\"cursor:hand;\"");
		  	    //设置上一页
		  	    if(currentPageNo <=1 || totalPage <=1){
		  	    }else{
		  	    	buffer.append(" onclick=\"document."+formName+".currentPageNo.value='"+(currentPageNo-1)+"';changePage('"+ nameSpace + ctx.getName() + ".action','"+this.getBusiId()+"','"+(currentPageNo-1)+"','"+otherParam.toString()+"');\"");
		  	    }
		  	  buffer.append("/></td>\n")
	          .append("    <td width=\"35\" align=\"center\" valign='middle'><input id=\"toPageNo\" type=\"text\" size=\"4\"  value='"+ currentPageNo +"' class=\"paginationbox_css\" onfocus=\"this.style.background='white';\" onkeypress=\"gotoPage(this,"+this.pageInfo.getTotalPage()+",'"+ nameSpace + ctx.getName() + ".action','"+this.getBusiId()+"','"+otherParam.toString()+"')\" onblur=\"if (!isInt(this)){this.value=1;};this.style.background='D7D2D3';\">\n")
	          .append("    <td width=\"25\" align=\"left\" valign='middle'><span class='smalltext'>/"+String.valueOf(totalPage)+"</span></td>\n") 
	    	  .append("    <td width=\"20\" align=\"left\" valign='middle'><img src=\"" + root + "/core/images/button_03.gif\" width=\"15\" height=\"15\" style=\"cursor:hand;\"");
		  	    //设置下一页
		  	    if (totalPage<=1 || currentPageNo>=totalPage){
		  	    }else{
		  	    	buffer.append(" onclick=\"document."+formName+".currentPageNo.value='"+(currentPageNo+1)+"';changePage('"+ nameSpace + ctx.getName() + ".action','"+this.getBusiId()+"','"+(currentPageNo+1)+"','"+otherParam.toString()+"');\"");
		  	    }
		  	  buffer.append("/></td>\n")
	          .append("    <td width=\"20\" align=\"left\" valign='middle'><img src=\"" + root + "/core/images/button_04.gif\" width=\"15\" height=\"15\" style=\"cursor:hand;\"");
		  	    //设置最后一页
		  	    if (totalPage<=1 || currentPageNo>=totalPage){
		  	    }else{
		  	    	buffer.append(" onclick=\"document."+formName+".currentPageNo.value='"+(totalPage)+"';changePage('"+ nameSpace + ctx.getName() + ".action','"+this.getBusiId()+"','"+(totalPage)+"','"+otherParam.toString()+"');\"");
		  	    }	          
		  	  buffer.append("/></td>\n")
	          .append("  </tr>\n") 
	          .append("</form>\n")
	    	  .append("</table>\n");
	    return buffer.toString(); 
	}

	public String getPagination() {
		return doPagination(this.formQryParamsMap);
	}

	/**
	 * 内部类，用于保存查询的信息，目前这部分信息保存到session中，只保存几个查询条件，占用很少的内存
	 * @author Administrator
	 *
	 */
	public boolean isCache() {
		return cache;
	}

	public void setCache(boolean cache) {
		this.cache = cache;
	}

	/**
	 * 初始扩展参数集合
	 * @return
	 */
	public HashMap getInitExtraParamsMap(){
		this._extraParamsMap.clear();
		return this._extraParamsMap;
	}
	
	/**
	 * 设置扩展参数
	 * 
	 * @param paramName
	 * @param paramVal
	 */
	public void setExtraParams(String paramName,String paramVal){
		this._extraParamsMap.put(paramName,paramVal);
	}
	
	/**
	 * 通过该函数获得查询条件的值，该函数用在页面上作为查询条件的额回显，或用在action中，从session中获得缓存的查询条件值
	 * @param condName
	 * @return
	 */
	public String getCondVal(String condName){
		ActionContext ctx = ActionContext.getContext();
		HashMap queryCacheMap = (HashMap)ctx.getSession().get(COMMONQUERY_CONDITION_SESSION_NAME);
		
		if (queryCacheMap!=null){
			QryConditionInfo qryConditionInfo = (QryConditionInfo)queryCacheMap.get(this.busiId);
			
			if (qryConditionInfo!=null){
				HashMap formParamsMap = qryConditionInfo.formParamMap;	
		
				if (formParamsMap!=null){
					if (formParamsMap.containsKey(condName)){
						return (String)formParamsMap.get(condName);
					}
		
				}
			}
		}
		
		return "";
	}

	public QueryService getQueryService() {
		return queryService;
	}

	public void setQueryService(QueryService queryService) {
		this.queryService = queryService;
	}

	public String getEncapType() {
		return encapType;
	}

	public void setEncapType(String encapType) {
		this.encapType = encapType;
	}

	public int getPageSize() {
		if (this.pageInfo!=null){
			return this.pageInfo.getPageSize();
		}else{
			return 0;
		}
	}

	public void setPageSize(int pageSize) {
		if (this.pageInfo!=null){
			this.pageInfo.setPageSize(pageSize);
		}		
	}
	
	/**
	 * 导出执行方法
	 * @throws Exception
	 */
	protected void performExport()throws Exception{
		ActionContext ctx = ActionContext.getContext();			
		
		String qryParamPrefix = qry_param_prefix.toUpperCase();	
		HashMap allParamsMap = new HashMap();

		Iterator it = ctx.getParameters().keySet().iterator();
		while(it.hasNext()){
			String keyName = (String)it.next();
			if (keyName.toUpperCase().startsWith(qryParamPrefix)){
				String[] vals = (String[])(ctx.getParameters().get(keyName));					
				if (vals!=null && vals.length>0){
					allParamsMap.put(keyName,vals[0]);
				}
			}
		}	
		it = this._extraParamsMap.keySet().iterator();
		while(it.hasNext()){
			String keyName = (String)it.next();
			allParamsMap.put(keyName,(String)this._extraParamsMap.get(keyName));
		}

		
		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.reset();
		
		response.setHeader("Content-Type",
				"application/vnd.ms-excel; charset=GBK");
		response.setHeader("Content-disposition",
				"attachment;filename=customerExport.csv");
		//头
		response.flushBuffer();
		
		QueryInfoBean queryInfoBean = (QueryInfoBean)QueryScriptDef.getQueryInfo(busiId);
		
		List columnList = queryInfoBean.getColumnList();
		outLineData(columnList,null,response,true);
		
		
		PageInfo exportPageInfo = new PageInfo(SystemProperties.getInstance().getExportPageSize());
		exportPageInfo.setCurrentPageNo(1);
		       
		//获得查询
		exportPageInfo = queryData(busiId, allParamsMap, exportPageInfo,this.encapType);
		
		outLineData(columnList,exportPageInfo.getSearchResult(),response,false);
		

		
		//csv输出
		
		int totalPage = exportPageInfo.getTotalPage();
		
		for(int i = 2;i<=totalPage; i++){
			exportPageInfo.setCurrentPageNo(i);
			exportPageInfo = queryData(busiId, allParamsMap, exportPageInfo,this.encapType);
			outLineData(columnList,exportPageInfo.getSearchResult(),response,false);
            //csv输出
		}
	
	}
	
	
	private void outLineData(List columnList,List valueList,HttpServletResponse response,boolean outHead) throws IOException{
		if (columnList==null){
			return;
		}
		if (outHead){
			
			boolean hasExported = false;
			for(int i = 0; i<columnList.size(); i++){
				ColumnInfoBean column = (ColumnInfoBean)columnList.get(i);
				if (column.isExport()){
					if (hasExported){
					    response.getWriter().print(",");
					}
					response.getWriter().print("\"" + this.getText(column.getTitle())+"\"");
					hasExported = true;
					
				}
				
		    }
			response.getWriter().println();
			response.flushBuffer();
			
		}else{
			if (valueList==null){
				return;
			}
			for (int m=0;m<valueList.size();m++){
				Object data = valueList.get(m);
				boolean hasExported = false;
				for(int i = 0; i<columnList.size(); i++){
					ColumnInfoBean column = (ColumnInfoBean)columnList.get(i);
					if (column.isExport()){
						if (hasExported){
						    response.getWriter().print(",");
						}
						if(Map.class.isAssignableFrom(data.getClass())){
							response.getWriter().print("\""+ column.getPrefix() + ((Map)data).get(column.getName())+"\"");
						}else{
							response.getWriter().print("\""+ column.getPrefix() + ((List)data).get(Integer.valueOf(column.getName()))+"\"");
						}
						hasExported = true;
						
					}
					
			    }
				response.getWriter().println();
				response.flushBuffer();
			}
		}

		
	}

	public String getOrderByScript() {
		return orderByScript;
	}

	public void setOrderByScript(String orderByScript) {
		this.orderByScript = orderByScript;
	}

	public String getSortField() {
		return sortField;
	}

	public void setSortField(String sortField) {
		this.sortField = sortField;
	}

	public String getSortMode() {
		return sortMode;
	}

	public void setSortMode(String sortMode) {
		this.sortMode = sortMode;
	}


	public String getBusiDataId() {
		Operator op=getCurrOperator();
		if(op!=null){
			if(op.getBusinessId()!=null){
				this.busiDataId=op.getBusinessId();
			}else{
				this.busiDataId="0";
			}
			
		}else{
			this.busiDataId="0";
		}
		return busiDataId;
	}

	public void setBusiDataId(String busiDataId) {
		Operator op=getCurrOperator();
		if(op!=null){
			if(op.getBusinessId()!=null){
				this.busiDataId=op.getBusinessId();
			}else{
				this.busiDataId="0";
			}
			
		}else{
			this.busiDataId="0";
		}
	}
}
